"""
发送请求
"""
import requests
import json


class ApiBase:
    def request(self, **kwargs):
        """
        发送请求
        """
        url = kwargs.get("url")
        payload = kwargs.get("payload")
        headers = kwargs.get("headers")
        method = kwargs.get("method")
        payload = json.dumps(payload)
        response = requests.request(method=method, url=url, headers=headers, data=payload)
        return self.make_response(response.text)

    def get_headers(self):
        """
        获取请求头
        """
        return {
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
            'Content-Type': 'application/json',
            'Accept': '*/*',
            'Host': 'a1.easemob.com',
            'Connection': 'keep-alive'
        }

    def make_response(self, result):
        """
        处理结果
        """
        return json.loads(result)
